package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.DishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminUserDishController")
@RequestMapping("/admin/dish")
@Slf4j
public class DishController {

    @Autowired
    DishService dishService;

    /**
     * 新增菜品
     * @param dto
     * @return
     */
    @PostMapping
    public Result addDish(@RequestBody DishDTO dto){
        log.info("新增菜品:{}",dto);
        return dishService.addDish(dto);
    }

    /**
     * 分页查询菜品
     * @param dishPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result page(DishPageQueryDTO dishPageQueryDTO){
        log.info("分页查询菜品:{}",dishPageQueryDTO);
        return dishService.dishPage(dishPageQueryDTO);
    }

    /**
     * 批量删除菜品
     * @param ids
     * @return
     */
    @DeleteMapping//这里一定要用@RequestParam,传回来的是http://localhost/api/dish?ids=71,70,69,68要用数组去接
    public Result deleteByIds(@RequestParam List<Long> ids){
        log.info("批量删除菜品:{}",ids);
        return dishService.deleteByIds(ids);
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id){
        log.info("批量删除菜品:{}",id);
        return dishService.getById(id);
    }


    @PutMapping
    public Result updateDish(@RequestBody DishDTO dto){
        log.info("修改菜品:{}",dto);
        return dishService.updateDish(dto);
    }


    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status , Long id){
        log.info("修改菜品状态:{} , {}",status , id);
        return dishService.updateStatus(status,id);
    }

    @GetMapping("/list")
    public Result getByCategoryId(Long categoryId){
        log.info("根据分类id查询菜品:{}" , categoryId);
        return dishService.getByCategoryId(categoryId);
    }

}
